namespace SubhadraSolutions.Sharp.Logging.LogSubscribers.Database
{
    using SubhadraSolutions.Sharp.Logging.Contracts;
    using SubhadraSolutions.Sharp.Logging.LogItems;
    using SubhadraSolutions.Sharp.Utils.Data.Common;
    using System.Collections.Generic;
    using System.Globalization;

    public class SimpleLogEntryDataReader : AbstractEnumeratorDataReader<LogStoreItem>, ILoggerDataReader
    {
        #region Properties

        public bool IsInitialized
        {
            get;
            private set;
        }

        #endregion Properties

        #region Indexers

        public override object this[int i]
        {
            get
            {
                switch (i)
                {
                    case 0:
                        return current.TimeStamp;

                    case 1:
                        return current.ThreadId.ToString(CultureInfo.InvariantCulture);

                    case 2:
                        return current.Severity.ToString();
                }
                var e = current.LogEntry as SimpleLogItem;
                if (e != null)
                {
                    switch (i)
                    {
                        case 3:
                            return e.Message;

                        case 4:
                            return (e.Exception == null ? null : e.Exception.ToString());
                    }
                }
                return null;
            }
        }

        #endregion Indexers

        #region Methods

        public void Initialize()
        {
            if (!IsInitialized)
            {
                initializeProtected();
                IsInitialized = true;
            }
        }

        public void SetColumnNames(IEnumerable<string> columnNames)
        {
            ColumnNames.Clear();
            ColumnNames.AddRange(columnNames);
        }

        public void SetProcessInstanceName(string processInstanceName)
        {
            //throw new System.NotImplementedException();
        }

        protected virtual void initializeProtected()
        {
        }

        #endregion Methods
    }
}